"""
将s分割成k个等长的子串，然后 重排，问是否能够形成t
先分割出来记录数量，然后对t，依次去查找即可
"""
class Solution:
    def isPossibleToRearrange(self, s: str, t: str, k: int) -> bool:
        D = {}
        N = len(s)
        k = N // k
        for i in range(0, N, k):
            tmp = s[i:i + k]
            if tmp in D:
                D[tmp] += 1
            else:
                D[tmp] = 1
        for i in range(0, N, k):
            tmp = t[i: i + k]
            if tmp in D:
                D[tmp] -= 1
                if D[tmp] == 0: D.pop(tmp)
            else:
                return False
        return True